- Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy path2043.Simple Bank System.go
44 lines (39 loc) · 823 Bytes
/
2043.Simple Bank System.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package leetcode
typeBankstruct {
accounts []int64
nint
}
funcConstructor(balance []int64) Bank {
returnBank{
accounts: balance,
n: len(balance),
}
}
func (this*Bank) Transfer(account1int, account2int, moneyint64) bool {
ifaccount1>this.n||account2>this.n {
returnfalse
}
ifthis.accounts[account1-1] <money {
returnfalse
}
this.accounts[account1-1] -=money
this.accounts[account2-1] +=money
returntrue
}
func (this*Bank) Deposit(accountint, moneyint64) bool {
ifaccount>this.n {
returnfalse
}
this.accounts[account-1] +=money
returntrue
}
func (this*Bank) Withdraw(accountint, moneyint64) bool {
ifaccount>this.n {
returnfalse
}
ifthis.accounts[account-1] <money {
returnfalse
}
this.accounts[account-1] -=money
returntrue
}